home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 12 / Amiga Format AFCD12 (Apr 1997, Issue 96).iso / -readerstuff- / manolis_pappas / mathfx / examples / polar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-29  |  1.4 KB  |  71 lines

  1. /* Illustration of 1-1 scaling for polar plot using MathFX library. */
  2. /* Copyright (©) 1995, The Xperts Group Inc. All Rights Reserved. */
  3. /* Author: Manolis S Pappas. */
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7.  
  8. main()
  9. {
  10.       int i,j;
  11.       float dtr, theta, dx, dy, r;
  12.       char text[3];
  13.       float x0[361], y0[361];
  14.       float x[361], y[361];
  15.  
  16.       dtr = 3.141592654/180.0;
  17.       for (i=0; i<=360; i++) {
  18.         x0[i] = cos(dtr * i);
  19.         y0[i] = sin(dtr * i);
  20.       }
  21.  
  22.       fxstar(1,1);
  23.  
  24. /* Set up viewport and window, but do not draw box */
  25.  
  26.       fxenv(-1.3,1.3,-1.3,1.3,1,-2);
  27.       for (i=1; i<=10; i++) {
  28.         for (j=0; j<=360; j++) {
  29.           x[j] = 0.1*i*x0[j];
  30.           y[j] = 0.1*i*y0[j];
  31.         }
  32.  
  33. /* Draw circles for polar grid */
  34.  
  35.         fxline(361,x,y);
  36.       }
  37.  
  38.       for (i=0; i<=11; i++) {
  39.         theta = 30.0*i;
  40.         dx = cos(dtr*theta);
  41.         dy = sin(dtr*theta);
  42.  
  43. /* Draw radial spokes for polar grid */
  44.  
  45.         fxjoin(0.0,0.0,dx,dy);
  46.         sprintf(text,"%d",round(theta));
  47.  
  48. /* Write labels for angle */
  49.  
  50.         if (dx >= 0) 
  51.           fxptex(dx,dy,dx,dy,-0.15,text);
  52.         else
  53.           fxptex(dx,dy,-dx,-dy,1.15,text);
  54.       }
  55.  
  56. /* Draw the graph */
  57.  
  58.       for (i=0; i<=360; i++) {
  59.         r = sin(dtr*(5*i));
  60.         x[i] = x0[i] * r;
  61.         y[i] = y0[i] * r;
  62.       }
  63.       fxline(361,x,y);
  64.  
  65.       fxmtex("t",2.0,0.5,0.5,"\\frPolar Plot - r(\\gh)=sin 5\\gh");
  66.  
  67. /* Close the plot at end */
  68.  
  69.       fxend();
  70. }
  71.